package com.ruizhong.PIW.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruizhong.PIW.service.FileService;
import com.ruizhong.PIW.utils.Result;
import com.ruizhong.PIW.utils.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;



@RestController
@RequestMapping("/api/file")
@CrossOrigin
@Slf4j
public class FileController {
    private final String FileAddressStagingArea = "FASA";
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private FileService fileService;
    private static final ObjectMapper mapper = new ObjectMapper();

    @PostMapping("/upload")
    public Result upload(MultipartFile file) {
        String url=fileService.uploadFile(file);
        return new Result(ResultCode.success, "上传成功", url);
    }

    @DeleteMapping("/deleteFile")
    public Result deleteFile(@RequestParam List<String> fileNameList) throws Exception {
        fileService.deleteFile(fileNameList);
        return new Result(ResultCode.success, "删除成功", null);
    }
}